{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b265b36d",
   "metadata": {},
   "source": [
    "---\n",
    "* 日期：2022-09-21\\week05（周三）\n",
    "* 课程：python\n",
    "* 记录人：zeng\n",
    "---\n",
    "# 本周学习内容\n",
    ">1. 数值（number)\n",
    ">>1. 定义\n",
    ">>2. 方法\n",
    "\n",
    ">2. 字符串（string)\n",
    ">>1. 定义\n",
    ">>2. 方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab396958",
   "metadata": {},
   "source": [
    "## 1.数值\n",
    "\n",
    ">1. 对数值进行分类\n",
    ">>1. 整数（int）\n",
    ">>2. 浮点型（float）\n",
    ">>3. 复数（complex）\n",
    ">2. 对数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c367c0cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整型\n",
    "a = 99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a60060cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b = 99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f85caabd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a+b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "99b466b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数（虚数）\n",
    "d =2+3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b0e2d34",
   "metadata": {},
   "source": [
    "## 2.字符串（str）\n",
    ">1. 定义\n",
    ">2. 方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6474ba9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ALONG <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'ALONG'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "254f93fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022 2022\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = 2022\n",
    "b ='2022'\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ccc1200f",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (Temp/ipykernel_51968/3434056166.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\樂\\AppData\\Local\\Temp/ipykernel_51968/3434056166.py\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "#  关于单引号和双引号引导\n",
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "31cfb7cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案1\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "309e3e31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案2 \\后面的内容是“符号”，转义， \\自动消失\n",
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a883eb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# *正则表达式，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4b6b79bb",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (Temp/ipykernel_51968/2693316446.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\樂\\AppData\\Local\\Temp/ipykernel_51968/2693316446.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    \"hello\u001b[0m\n\u001b[1;37m          ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "\"hello\n",
    "world\n",
    "\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "50e3746b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包含任何文本\n",
    "# 作用：\n",
    "# 1. 保持原数据的结构，包含符号，换行等。 \n",
    "# 2. 可以用来做代码注释。\n",
    "NFU_招投标_HTML = \"\"\"\n",
    "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
    "    </a>\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "89212681",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
      "    </a>\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(NFU_招投标_HTML)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1007f48a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "### 三个引号来代码注释\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "页面后缀 = \".htm\"\n",
    "page = 5\n",
    "\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀)  # 字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)\n",
    "\"\"\"\n",
    "\n",
    "print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b34dd47",
   "metadata": {},
   "source": [
    "### 2.1 字符串的运算法则\n",
    ">1. 字符串的拼接  \n",
    "\n",
    ">2. ##### <font color=\"red\">字符串的有序性</font>  \n",
    "\n",
    ">3. enumerate：枚举\n",
    ">4. in 可以查询成员对象是否存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b059760c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'helloworld'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串的拼接\n",
    "\"hello\" + \"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f80d0b74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好6，老六\n",
      "你好6，牛的\n"
     ]
    }
   ],
   "source": [
    "#实践\n",
    "text = \"你好6，\"\n",
    "for i in [\"老六\",\"牛的\"]:\n",
    "    result = text+i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8a28c43",
   "metadata": {},
   "source": [
    "* 取值：\n",
    ">1. 取单个值\n",
    ">2. 切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "8096e335",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "eac0bdc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5c69895d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "e20ff032",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "270e5751",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "708329ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "160d0c15",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "426386aa",
   "metadata": {},
   "source": [
    "#### <font color=\"red\">期中测试</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c4fb1b38",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广州 这个文本\n",
      "存在 广州 这个文本\n"
     ]
    }
   ],
   "source": [
    "# 实践：请检查 广州是否在 地址 里面？\n",
    "# 检查 i 是否是广，然后判断 i[index+1]下一个索引值的内容是否是州\n",
    "\n",
    "# 方法：enumerate：枚举\n",
    "for index,value in enumerate(地址):\n",
    "    if value == \"广\":\n",
    "        if 地址[index+1] == \"州\":\n",
    "            print(\"存在 广州 这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "227a9147",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 从广 这个文本\n"
     ]
    }
   ],
   "source": [
    "for index,value in enumerate(地址):\n",
    "    if value == \"化\":\n",
    "        if 地址[index-4] == \"广\":\n",
    "            print(\"存在 从广 这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "420ac53f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法：in 可以查询成员的变量\n",
    "print(\"广州\" in 地址)\n",
    "print(\"ALONG\" in 地址)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "7a947628",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<built-in method capitalize of str object at 0x0000019E9494CBF0>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#\n",
    "##1. 首字母变大写\n",
    "##2. 检查字符出现的次数\n",
    "print(\"along\".capitalize)\n",
    "地址.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07112e98",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f6822e4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
